package com.cmc.cloud.cmclink.doc.controller.admin.special;

import cn.hutool.core.bean.BeanUtil;
import com.cmc.cloud.cmclink.doc.constants.UrlConstants;
import com.cmc.cloud.cmclink.doc.entity.VesselOffHireMaintenanceDO;
import com.cmc.cloud.cmclink.doc.service.VesselOffHireMaintenanceService;
import com.cmc.cloud.cmclink.doc.vo.vesseloffhiremaintenancevo.VesselOffHireMaintenanceCreateReqVO;
import com.cmc.cloud.cmclink.doc.vo.vesseloffhiremaintenancevo.VesselOffHireMaintenancePageReqVO;
import com.cmc.cloud.cmclink.doc.vo.vesseloffhiremaintenancevo.VesselOffHireMaintenanceRespVO;
import com.cmc.cloud.cmclink.doc.vo.vesseloffhiremaintenancevo.VesselOffHireMaintenanceUpdateReqVO;
import com.cmes.framework.biz.advice.annotations.UseResponsePropertyAdvice;
import com.cmes.framework.common.pojo.CommonResult;
import com.cmes.framework.common.pojo.PageResult;
import com.cmes.framework.operatelog.core.annotations.OperateLog;
import com.cmes.framework.operatelog.core.enums.OperateTypeEnum;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.validation.Valid;
import java.util.Collection;
import java.util.List;


/**
 * 整船禁接的船舶维护前端接口Controller
 * 
 * @author codegen
 */
@Tag(name = "管理后台 - 整船禁接的船舶维护")
@RestController
@Validated
@RequestMapping(UrlConstants.APPLICATION_URL+"/vesselOffHireMaintenance")
public class VesselOffHireMaintenanceController {

    @Resource
    private VesselOffHireMaintenanceService vesselOffHireMaintenanceService;

    @Operation(summary = "创建整船禁接的船舶维护")
	@PostMapping("/create")
    @PreAuthorize("@ss.hasPermission('doc:maintenance-ships:add')")
    @OperateLog(name = "创建整船禁接的船舶维护", type = OperateTypeEnum.CREATE)
    public CommonResult<Void> createVesselOffHireMaintenance(@Valid @RequestBody VesselOffHireMaintenanceCreateReqVO createReqVO) {
        vesselOffHireMaintenanceService.createVesselOffHireMaintenance(createReqVO);
        return CommonResult.success();
    }

    @Operation(summary = "更新整船禁接的船舶维护")
	@PostMapping("/update")
    @PreAuthorize("@ss.hasPermission('doc:maintenance-ships:edit')")
    @OperateLog(name = "更新整船禁接的船舶维护", type = OperateTypeEnum.UPDATE)
    public CommonResult<Void> updateVesselOffHireMaintenance(@Valid @RequestBody VesselOffHireMaintenanceUpdateReqVO updateReqVO) {
        vesselOffHireMaintenanceService.updateVesselOffHireMaintenance(updateReqVO);
        return CommonResult.success();
    }

    @Operation(summary = "删除整船禁接的船舶维护")
	@PostMapping("/delete/{id}")
    @PreAuthorize("@ss.hasPermission('doc:maintenance-ships:delete')")
    @Parameter(name = "id", description = "编号", required = true)
    @OperateLog(name = "删除整船禁接的船舶维护", type = OperateTypeEnum.DELETE)
    public CommonResult<Void> deleteVesselOffHireMaintenance(@PathVariable("id") Long id) {
        vesselOffHireMaintenanceService.deleteVesselOffHireMaintenance(id);
        return CommonResult.success();
    }

    @Operation(summary = "获得整船禁接的船舶维护")
	@GetMapping("/getById/{id}")
    @PreAuthorize("@ss.hasPermission('doc:maintenance-ships:edit')")
    @Parameter(name = "id", description = "编号", required = true, example = "1024")
    @OperateLog(name = "获得整船禁接的船舶维护", type = OperateTypeEnum.GET)
    public CommonResult<VesselOffHireMaintenanceRespVO> getVesselOffHireMaintenance(@PathVariable("id") Long id) {
        VesselOffHireMaintenanceDO vesselOffHireMaintenance = vesselOffHireMaintenanceService.getVesselOffHireMaintenance(id);
        return CommonResult.success(BeanUtil.copyProperties(vesselOffHireMaintenance, VesselOffHireMaintenanceRespVO.class));
    }

    @Operation(summary = "获得整船禁接的船舶维护列表")
	@GetMapping("/listAll")
    @Parameter(name = "ids", description = "编号列表", required = true, example = "1024,2048")
    @OperateLog(name = "获得整船禁接的船舶维护列表", type = OperateTypeEnum.GET)
    public CommonResult<List<VesselOffHireMaintenanceRespVO>> getVesselOffHireMaintenanceList(@RequestParam("ids") Collection<Long> ids) {
        List<VesselOffHireMaintenanceDO> list = vesselOffHireMaintenanceService.getVesselOffHireMaintenanceList(ids);
        return CommonResult.success(BeanUtil.copyToList(list, VesselOffHireMaintenanceRespVO.class));
    }

    @Operation(summary = "获得整船禁接的船舶维护分页")
	@PostMapping("/getPage")
    @PreAuthorize("@ss.hasPermission('doc:maintenance-ships:search')")
    @OperateLog(name = "获得整船禁接的船舶维护分页", type = OperateTypeEnum.GET)
    @UseResponsePropertyAdvice
    public CommonResult<PageResult<VesselOffHireMaintenanceRespVO>> getVesselOffHireMaintenancePage(@RequestBody @Valid VesselOffHireMaintenancePageReqVO pageVO) {
        PageResult<VesselOffHireMaintenanceRespVO> pageResult = vesselOffHireMaintenanceService.getVesselOffHireMaintenancePage(pageVO);
        return CommonResult.success(pageResult);
    }
}
